package com.xl.baseMethod;

import lombok.extern.slf4j.Slf4j;

import static java.lang.Thread.sleep;

/**
 * JdkVersion: 1.8
 * Author: lei·xie
 * Created: 2024/8/5 0002 10:22
 * Description: 基本方法 interrupt打断正常线程
 */
@Slf4j(topic = "b.Test9")
public class ThreadDemo09 {
    public static void main(String[] args) throws InterruptedException{
        test1();
    }

    private static void test1() {
        Thread t1 = new Thread(() -> {
            while (true) {
                log.debug("执行..");
                boolean success = Thread.currentThread().isInterrupted();
                if (success) {
                    log.debug("被打断了，线程退出");
                    break;
                }
            }
        },"t1");
        t1.start();
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.debug("interrupt..");
        t1.interrupt();
        log.debug("打断标记：{}",t1.isInterrupted());
    }
}
